VERSION 5.00
Object = "{86CF1D34-0C5F-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSCOMCT2.OCX"
Begin VB.Form frmMoneyExchange 
   Caption         =   "Money Exchange"
   ClientHeight    =   8550
   ClientLeft      =   60
   ClientTop       =   450
   ClientWidth     =   12735
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MDIChild        =   -1  'True
   ScaleHeight     =   8550
   ScaleWidth      =   12735
   Begin VB.ComboBox cboType 
      Height          =   315
      Left            =   6360
      TabIndex        =   38
      Top             =   1560
      Width           =   2772
   End
   Begin VB.TextBox txtBank 
      Height          =   492
      Left            =   12000
      TabIndex        =   37
      Top             =   2040
      Visible         =   0   'False
      Width           =   972
   End
   Begin VB.TextBox txtDate 
      Height          =   492
      Left            =   10320
      TabIndex        =   36
      Top             =   1200
      Visible         =   0   'False
      Width           =   972
   End
   Begin VB.TextBox txtID 
      Height          =   492
      Left            =   9960
      TabIndex        =   35
      Top             =   240
      Visible         =   0   'False
      Width           =   972
   End
   Begin VB.TextBox txtROE 
      Height          =   375
      Left            =   1800
      TabIndex        =   33
      Top             =   2400
      Width           =   2775
   End
   Begin VB.CheckBox Check1 
      Caption         =   "Is Bank"
      Height          =   255
      Left            =   6360
      TabIndex        =   32
      Top             =   2040
      Width           =   852
   End
   Begin VB.TextBox txtVND 
      Height          =   375
      Left            =   1800
      TabIndex        =   3
      Top             =   1920
      Width           =   2775
   End
   Begin VB.TextBox txtInumber 
      Height          =   372
      Left            =   6360
      TabIndex        =   7
      Top             =   1080
      Width           =   3012
   End
   Begin VB.TextBox txtDescription 
      Height          =   372
      Left            =   6360
      TabIndex        =   8
      Top             =   2880
      Width           =   3012
   End
   Begin VB.TextBox txtTotalNumber 
      Height          =   372
      Left            =   6360
      TabIndex        =   21
      Top             =   3360
      Width           =   3012
   End
   Begin VB.TextBox txtDocument 
      Height          =   372
      Left            =   6360
      TabIndex        =   9
      Top             =   3840
      Width           =   3012
   End
   Begin VB.TextBox txtDoneBy 
      Height          =   372
      Left            =   1800
      TabIndex        =   4
      Top             =   2880
      Width           =   2772
   End
   Begin VB.TextBox txtReceiver 
      Height          =   372
      Left            =   1800
      TabIndex        =   5
      Top             =   3360
      Width           =   2772
   End
   Begin VB.TextBox txtCompanyTitle 
      Height          =   372
      Left            =   1800
      TabIndex        =   6
      Top             =   3840
      Width           =   2772
   End
   Begin VB.TextBox txtTotalWords 
      Height          =   372
      Left            =   1800
      TabIndex        =   20
      Top             =   4440
      Width           =   7575
   End
   Begin VB.ComboBox cmbOFFC 
      Height          =   315
      Left            =   1800
      TabIndex        =   1
      Top             =   960
      Width           =   2772
   End
   Begin VB.TextBox txtUSD 
      Height          =   372
      Left            =   1800
      TabIndex        =   2
      Top             =   1440
      Width           =   2772
   End
   Begin VB.CommandButton cmdSave 
      Caption         =   "&Save"
      Height          =   372
      Left            =   9000
      TabIndex        =   10
      Top             =   5400
      Width           =   1332
   End
   Begin VB.CommandButton cmdDone 
      Caption         =   "&Close"
      Height          =   372
      Left            =   10560
      TabIndex        =   12
      Top             =   5400
      Width           =   972
   End
   Begin MSComCtl2.DTPicker DTPicker1 
      Height          =   375
      Left            =   1800
      TabIndex        =   0
      Top             =   480
      Width           =   1575
      _ExtentX        =   2778
      _ExtentY        =   661
      _Version        =   393216
      Format          =   21102593
      CurrentDate     =   39566
   End
   Begin VB.Frame Frame2 
      Caption         =   "Control Panel"
      Height          =   1332
      Left            =   360
      TabIndex        =   11
      Top             =   4920
      Width           =   12012
      Begin VB.CommandButton Command6 
         Caption         =   "&Delete"
         Height          =   372
         Left            =   600
         TabIndex        =   16
         Top             =   480
         Width           =   1572
      End
      Begin VB.CommandButton cmdClearDetail 
         Caption         =   "Clea&R"
         Height          =   372
         Left            =   2400
         TabIndex        =   15
         Top             =   480
         Width           =   1332
      End
      Begin VB.CommandButton Command8 
         Caption         =   "&Back"
         Height          =   372
         Left            =   4680
         TabIndex        =   14
         Top             =   480
         Width           =   1092
      End
      Begin VB.CommandButton Command9 
         Caption         =   "&Preview and Print"
         Height          =   372
         Left            =   6000
         TabIndex        =   13
         Top             =   480
         Width           =   1812
      End
   End
   Begin VB.Label Label13 
      Caption         =   "ROE"
      Height          =   255
      Left            =   1200
      TabIndex        =   34
      Top             =   2400
      Width           =   495
   End
   Begin VB.Label Label12 
      Caption         =   "VND"
      Height          =   255
      Left            =   1200
      TabIndex        =   31
      Top             =   1920
      Width           =   495
   End
   Begin VB.Label Label1 
      Alignment       =   1  'Right Justify
      Caption         =   "Date"
      Height          =   255
      Index           =   1
      Left            =   1320
      TabIndex        =   30
      Top             =   480
      Width           =   375
   End
   Begin VB.Label Label4 
      Alignment       =   1  'Right Justify
      Caption         =   "Done by"
      Height          =   252
      Left            =   720
      TabIndex        =   29
      Top             =   2880
      Width           =   852
   End
   Begin VB.Label Label5 
      Alignment       =   1  'Right Justify
      Caption         =   "Receiver/Payer"
      Height          =   252
      Left            =   360
      TabIndex        =   28
      Top             =   3360
      Width           =   1212
   End
   Begin VB.Label Label6 
      Alignment       =   1  'Right Justify
      Caption         =   "Company Title"
      Height          =   252
      Left            =   360
      TabIndex        =   27
      Top             =   3840
      Width           =   1212
   End
   Begin VB.Label Label7 
      Alignment       =   1  'Right Justify
      Caption         =   "inumber"
      Height          =   252
      Left            =   5400
      TabIndex        =   26
      Top             =   1200
      Width           =   732
   End
   Begin VB.Label Label8 
      Alignment       =   1  'Right Justify
      Caption         =   "Description"
      Height          =   255
      Left            =   5280
      TabIndex        =   25
      Top             =   2880
      Width           =   855
   End
   Begin VB.Label Label9 
      Alignment       =   1  'Right Justify
      Caption         =   "Total in number"
      Height          =   255
      Left            =   4920
      TabIndex        =   24
      Top             =   3360
      Width           =   1215
   End
   Begin VB.Label Label10 
      Alignment       =   1  'Right Justify
      Caption         =   "Document attached"
      Height          =   255
      Left            =   4680
      TabIndex        =   23
      Top             =   3840
      Width           =   1455
   End
   Begin VB.Label Label11 
      Alignment       =   1  'Right Justify
      Caption         =   "Total in words"
      Height          =   255
      Left            =   480
      TabIndex        =   22
      Top             =   4440
      Width           =   1095
   End
   Begin VB.Label Label1 
      Caption         =   "OFFC"
      Height          =   255
      Index           =   0
      Left            =   1200
      TabIndex        =   19
      Top             =   960
      Width           =   495
   End
   Begin VB.Label Label2 
      Caption         =   "USD"
      Height          =   255
      Left            =   1200
      TabIndex        =   18
      Top             =   1440
      Width           =   495
   End
   Begin VB.Label Label3 
      Caption         =   "Type"
      Height          =   252
      Left            =   5640
      TabIndex        =   17
      Top             =   1680
      Width           =   492
   End
End
Attribute VB_Name = "frmMoneyExchange"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False

Private Sub cmdClearDetail_Click()
    Call clearTextbox
End Sub

Private Sub cmdDone_Click()
    If cmbOFFC.Text = "" And txtUSD.Text = "" And txtVND.Text = "" And txtROE.Text = "" And txtDoneBy.Text = "" And txtReceiver.Text = "" And txtCompanyTitle.Text = "" And txtInumber.Text = "" And cboType.Text = "" And txtDescription.Text = "" And txtDocument.Text = "" Then
        Unload Me
        Exit Sub
    End If
    If MsgBox("Do you save the information???", vbYesNo + vbQuestion, "Note...") = vbYes Then
        If cmbOFFC.Text = "" Or txtUSD.Text = "" Or txtVND.Text = "" Or txtROE.Text = "" Or txtDoneBy.Text = "" Or txtReceiver.Text = "" Or txtCompanyTitle.Text = "" Or txtInumber.Text = "" Or cboType.Text = "" Or txtDescription.Text = "" Or txtDocument.Text = "" Then
            MsgBox "Not enough information, check again!!!"
            Exit Sub
        Else
            Call cmdSave_Click
        End If
    Else
        Unload Me
        Exit Sub
    End If
End Sub
Private Function addROE(roeDate As String, ROE As Variant, loginID As String) As Boolean
On Error GoTo L
Dim sql As String
Dim rs As New ADODB.Recordset
sql = "Select * from roe where dateroe ='" & roeDate & "'"
Set rs = adoConnection.Execute(sql)
If Not rs.EOF Then
    If MsgBox("ROE of this date is already in database, do you want to overwite this one?", vbQuestion + vbYesNo, "Add ROE question") = vbYes Then
        sql = "delete * from roe where dateroe ='" & roeDate & "'"
        adoConnection.Execute (sql)
    Else
        addROE = False
        Exit Function
    End If
End If
sql = "insert into roe(dateROE,roe,loginID) values(" & roeDate & "," & ROE & ",'" & loginID & "')"
adoConnection.Execute sql
addROE = True
Exit Function
L:
addROE = False

End Function

Private Sub cmdSave_Click()
    Dim sql As String
If CheckText = True Then
    txtid.Text = 1
    If Check1.Value = 1 Then
        txtBank.Text = B
    Else
        txtBank.Text = C
    End If
    On Error GoTo Errp
        txtDate.Text = ""
        txtDate.Text = txtDate.Text & DTPicker1.Year
        If DTPicker1.Year > 2000 Then
            txtDate.Text = Val(txtDate.Text) - 2000
            If txtDate.Text < 10 Then
                txtDate.Text = "0" & txtDate.Text
            End If
        End If
        If DTPicker1.Month < 10 Then
            txtDate.Text = txtDate.Text & "0" & DTPicker1.Month
        Else
                txtDate.Text = txtDate.Text & DTPicker1.Month
        End If
        If DTPicker1.Day < 10 Then
                    txtDate.Text = txtDate & "0" & DTPicker1.Day
        Else
                    txtDate.Text = txtDate.Text & DTPicker1.Day
        End If
    Set gRs = New ADODB.Recordset
    sql = "INSERT INTO MoneyExchange(ID,moffc,mnumber,mdate,musd,mvnd,ROE,isBank,mType,doneby,receiverpayer,ctitle,des,tnumber,twords,docattached) VALUES('" & txtid.Text & "','" & cmbOFFC.Text & "','" & txtReceiver.Text & "','" & txtDate.Text & "','" & txtUSD.Text & "','" & txtVND.Text & "','" & txtROE.Text & "','" & txtBank.Text & "','" & cboType.Text & "','" & txtDoneBy.Text & "','" & txtReceiver.Text & "','" & txtCompanyTitle.Text & "','" & txtDescription.Text & "','" & txtTotalNumber.Text & "','" & txtTotalWords.Text & "','" & txtDocument.Text & "')"
    adoConnection.Execute sql
If Len(Trim(txtUSD.Text)) >= 2 Then
    If Left(Trim(txtUSD.Text), 1) = "-" Then
            If MsgBox("Do your want to add this ROE to database? (Y/N)", vbQuestion + vbYesNo, "ROE message") = vbYes Then
                If addROE(txtDate.Text, txtROE.Text, "System") Then
                    MsgBox "ROE Add successfully", vbInformation + vbOKOnly, "ROE message"
                Else
                    MsgBox "ROE add unsuccessfull", vbInformation + vbOKOnly, "ROE message"
                End If
            End If
    End If
End If
Errp:
    MsgBox err.Description
    cmdSave.Enabled = False
End If
End Sub

Private Sub Form_Load()
    Call KetNoi
    txtTotalNumber.Enabled = False
    txtTotalWords.Enabled = False
    DTPicker1.Value = Date
End Sub
Public Sub clearTextbox()
    txtUSD.Text = ""
    txtVND.Text = ""
    txtROE.Text = ""
    txtDoneBy.Text = ""
    txtReceiver.Text = ""
    txtCompanyTitle.Text = ""
    txtInumber.Text = ""
    cboType.Text = ""
    Check1.Value = 0
    txtDescription.Text = ""
    txtTotalNumber = ""
    txtDocument.Text = ""
    txtTotalWords = ""
End Sub
'=================================================
Function SpellNumber(ByVal MyNumber)
          Dim Dollars, Cents, temp
          Dim DecimalPlace, Count

          ReDim Place(9) As String
          Place(2) = " Thousand "
          Place(3) = " Million "
          Place(4) = " Billion "
          Place(5) = " Trillion "

          ' String representation of amount.
          MyNumber = Trim(str(MyNumber))

          ' Position of decimal place 0 if none.
          DecimalPlace = InStr(MyNumber, ".")
          ' Convert cents and set MyNumber to dollar amount.
          If DecimalPlace > 0 Then
              Cents = GetTens(Left(Mid(MyNumber, DecimalPlace + 1) & _
                  "00", 2))
              MyNumber = Trim(Left(MyNumber, DecimalPlace - 1))
          End If

          Count = 1
          Do While MyNumber <> ""
              temp = GetHundreds(Right(MyNumber, 3))
              If temp <> "" Then Dollars = temp & Place(Count) & Dollars
              If Len(MyNumber) > 3 Then
                  MyNumber = Left(MyNumber, Len(MyNumber) - 3)
              Else
                  MyNumber = ""
              End If
              Count = Count + 1
          Loop

          Select Case Dollars
              Case ""
                  Dollars = "No Dollars"
              Case "One"
                  Dollars = "One Dollar"
              Case Else
                  Dollars = Dollars & " Dollars"
          End Select

          Select Case Cents
              Case ""
                  Cents = " and No Cents"
              Case "One"
                  Cents = " and One Cent"
              Case Else
                  Cents = " and " & Cents & " Cents"
          End Select

          SpellNumber = Dollars & Cents
      End Function
      Function GetHundreds(ByVal MyNumber)
          Dim Result As String

          If Val(MyNumber) = 0 Then Exit Function
          MyNumber = Right("000" & MyNumber, 3)

          ' Convert the hundreds place.
          If Mid(MyNumber, 1, 1) <> "0" Then
              Result = GetDigit(Mid(MyNumber, 1, 1)) & " Hundred "
          End If

          ' Convert the tens and ones place.
          If Mid(MyNumber, 2, 1) <> "0" Then
              Result = Result & GetTens(Mid(MyNumber, 2))
          Else
              Result = Result & GetDigit(Mid(MyNumber, 3))
          End If

          GetHundreds = Result
      End Function


     Function GetTens(TensText)
          Dim Result As String

          Result = ""           ' Null out the temporary function value.
          If Val(Left(TensText, 1)) = 1 Then   ' If value between 10-19...
              Select Case Val(TensText)
                  Case 10: Result = "Ten"
                  Case 11: Result = "Eleven"
                  Case 12: Result = "Twelve"
                  Case 13: Result = "Thirteen"
                  Case 14: Result = "Fourteen"
                  Case 15: Result = "Fifteen"
                  Case 16: Result = "Sixteen"
                  Case 17: Result = "Seventeen"
                  Case 18: Result = "Eighteen"
                  Case 19: Result = "Nineteen"
                  Case Else
              End Select
          Else                                 ' If value between 20-99...
              Select Case Val(Left(TensText, 1))
                  Case 2: Result = "Twenty "
                  Case 3: Result = "Thirty "
                  Case 4: Result = "Forty "
                  Case 5: Result = "Fifty "
                  Case 6: Result = "Sixty "
                  Case 7: Result = "Seventy "
                  Case 8: Result = "Eighty "
                  Case 9: Result = "Ninety "
                  Case Else
              End Select
              Result = Result & GetDigit _
                  (Right(TensText, 1))  ' Retrieve ones place.
          End If
          GetTens = Result
      End Function

      Function GetDigit(Digit)
          Select Case Val(Digit)
              Case 1: GetDigit = "One"
              Case 2: GetDigit = "Two"
              Case 3: GetDigit = "Three"
              Case 4: GetDigit = "Four"
              Case 5: GetDigit = "Five"
              Case 6: GetDigit = "Six"
              Case 7: GetDigit = "Seven"
              Case 8: GetDigit = "Eight"
              Case 9: GetDigit = "Nine"
              Case Else: GetDigit = ""
          End Select
      End Function
      
      Function Num2Text(s)
    Dim so
    Dim hang
    so = Array(" khong ", "mot", "hai", "ba", "bon", "nam", "sau", "bay", "tam", "chin")
    hang = Array("", "nghin", "trieu", "ti")
    Dim i
    Dim j
    Dim donvi
    Dim chuc
    Dim tram
    Dim str
    str = ""
    i = Len(s)
    j = 0
    Do While j <= (i - 1)
        If Left(s, 1) = "0" Then
            s = Right(s, i - j)
        End If
     j = j + 1
    Loop
    If s = "0" Then
        Num2Text = so(0)
        Exit Function
    End If
    i = Len(s)
    If i = 0 Then
        str = ""
    Else
        j = 0
        Do While i > 0
            donvi = Int(Mid(s, i, 1))
            i = i - 1
            If i > 0 Then
                chuc = Int(Mid(s, i, 1))
            Else
                chuc = -1
            End If
            i = i - 1
            If i > 0 Then
                tram = Int(Mid(s, i, 1))
            Else
                tram = -1
            End If
            i = i - 1
            If donvi > 0 Or chuc > 0 Or tram > 0 Or (j Mod 3 = 0) Then
                If j Mod 3 <> 0 Then
                    str = hang((j - 1) Mod 3 + 1) & " " & str
                Else
                    If True Then
                        Dim temp
                        Dim k
                        temp = ""
                        For k = 1 To j \ 3
                            temp = " ti" + temp
                        Next
                        str = temp + ", " & str
                    End If
                End If
            End If
            j = j + 1
            If donvi = 1 And chuc > 1 Then
                str = "mot" & " " & str
            Else
                If donvi = 5 And chuc > 0 Then
                    str = "lam" & " " & str
                ElseIf donvi > 0 Then
                    str = so(donvi) & " " & str
                End If
            End If
            If chuc < 0 Then
                Exit Do
            Else
                If chuc = 0 And donvi > 0 Then
                    str = "le" & " " & str
                ElseIf chuc = 1 Then
                    str = "muoi" & " " & str
                ElseIf chuc > 1 Then
                    str = so(chuc) & " " & "muoi" & " " & str
                End If
            End If
            If tram < 0 Then
                Exit Do
            Else
                If tram > 0 Or chuc > 0 Or donvi > 0 Then
                    str = so(tram) & " " & "tram" & " " & str
                End If
            End If
        Loop
    End If
    Do While str <> Replace(str, ",  ti", ",")
        str = Replace(str, ",  ti", ", ")
    Loop
    Do While str <> Replace(str, ", ,", ",")
        str = Replace(str, ", ,", ",")
    Loop
    str = Trim(str)
    str = UCase(Left(str, 1)) & Right(str, Len(str) - 1)
    Num2Text = Left(str, Len(str) - 1) + " "
End Function


Private Sub txtTotalNumber_Change()
    If txtTotalNumber.Text = "" Then
        txtTotalWords.Text = ""
    Else
        txtTotalWords.Text = Num2Text(txtTotalNumber.Text) & " Vnd"
    End If
End Sub
Private Function CheckText() As Boolean
    Dim strr As String
    Dim CheckValue As Integer
    Dim check As Integer
    CheckValue = 0
    strr = ""
    If cmbOFFC.Text = "" Then
        strr = strr & "Choose a valid in OFFC"
    End If
    If txtUSD.Text = "" Then
        CheckValue = 1
        strr = strr & Chr(13) & "Enter a valid in USD"
    End If
    If Not IsNumeric(txtUSD.Text) And CheckValue = 0 Then
        strr = strr & Chr(13) & "You entered an invalid USD"
    End If
    If txtVND.Text = "" Then
        CheckValue = 2
        strr = strr & Chr(13) & "Enter a valid in VND"
    End If
    If Not IsNumeric(txtVND.Text) And CheckValue <> 2 Then
        strr = strr & Chr(13) & "You entered an invalid VND"
    End If
    If txtROE.Text = "" Then
        CheckValue = 3
        strr = strr & Chr(13) & "Enter a valid in ROE"
    End If
    If Not IsNumeric(txtROE.Text) And CheckValue <> 3 Then
        strr = strr & Chr(13) & "You entered an invalid ROE"
    End If
    If txtDoneBy.Text = "" Then
        strr = strr & Chr(13) & "Enter a valid value in Done By"
    End If
    If txtReceiver.Text = "" Then
        strr = strr & Chr(13) & "Enter a valid value in Receiver/Payer"
    End If
    If txtCompanyTitle.Text = "" Then
        strr = strr & Chr(13) & "Enter a valid value in Company Title"
    End If
    If txtInumber.Text = "" Then
        strr = strr & Chr(13) & "Enter a valid value in Inumber"
    End If
    If cboType.Text = "" Then
        strr = strr & Chr(13) & "Enter a valid value in Type"
    End If
    If txtDescription.Text = "" Then
        strr = strr & Chr(13) & "Enter a valid value in Description"
    End If
    If txtDocument.Text = "" Then
        CheckValue = 5
        strr = strr & Chr(13) & "Enter a valid in Document Attached"
    End If
    If Not IsNumeric(txtDocument.Text) And CheckValue <> 5 Then
        strr = strr & Chr(13) & "You entered an invalid Document Attached"
    End If
    If strr <> "" Then
        MsgBox strr
        CheckTextDetail = False
    Else
        CheckTextDetail = True
    End If
    
End Function
